<?php
namespace app\index\controller;
use think\Controller;
use think\Session;
class Index extends Controller
{

    public function __construct(){
        parent::__construct();
    }



    public function index()
    {
        // $this->error('sdf','index/index');die;
        return $this->fetch();
    }

    public function login(){
        //接收数据 判定用户信息
        $user = db('user')->where('name','=',$_POST['name'])->where('pass','=',$_POST['pass'])->find();
        // $a = db('user')->where('id','>',0)->select();
        if(!$user){
            echo  "<script>alert('用户名或密码错误')</script>";
            return $this->fetch('index/index');
        }
        if($user['class']=='超级管理员'){
            // echo  "<script>alert('欢迎您超级管理员')</script>";
            //发送部门列表到adminPage
            $classList = db('class')->select();
            $this->assign('classList',$classList);
            return $this->fetch('homePage/adminPage');
        }else{
            //初始登录信息全部存在session中 通过Mycontroller里的__contruct()发送前台
            Session::set('userid',$user['id']);
            return action('UserIndex/index');
        }
    }



    public function outlogin(){
        //删除缓存 跳转登录页
        Session::clear();
        return $this->fetch('index/index');
    }
}
